<template>
	<view class="cashOut">
		<view class="amount">
			<view class="tit">提现金额</view>
			<view class="inp">
				<view class="rmb">
					￥
				</view>
				<input class="cashinput" type="number" v-model.trim="money" placeholder="请输入提现金额"
					placeholder-class="placStyle" />
				<view class="right-btn" @click="money = userInfo.money">
					全部
				</view>
			</view>
			<view class="modelTip">
				当前可提现金额￥{{userInfo.money}}
			</view>
		</view>

		<view v-if="!is_examine" class="way">
			<view class="tit">提现方式
			</view>
			<view class="item">
				<image src="https://miaoyao-oss.oss-cn-hangzhou.aliyuncs.com/profitTool/zfbLogo.png" mode="scaleToFill">
				</image>
				<text>支付宝</text>
			</view>
		</view>

		<view class="pageTips">
			<view class="tit">提现规则</view>
			<view class="value">1、一般工作日72小时内处理</view>
			<view class="value">2、如超时未处理，请联系客服</view>
		</view>

		<view class="confirm-bar" @click="doWithdrawal">
			立即提现
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				money: "",
				userInfo: uni.getStorageSync("user"),
				is_examine: uni.getStorageSync("is_examine"),
			}
		},
		methods: {
			//发起提现
			async doWithdrawal() {
				if (!this.money < 0) {
					uni.showToast({
						title: `提现金额应大于0元！`,
						icon: 'none'
					});
					return
				}
				if (!this.userInfo.real_name || !this.userInfo.alipay_account) {
					uni.showToast({
						title: '真实姓名和收款账号信息不能为空~',
						icon: 'none'
					})
					return
				}
				uni.showModal({
					title: '提示',
					content: '确认提现？',
					success: async (res) => {
						if (res.confirm) {
							let res1 = await this.$http("api/user/doWithdrawal", {
								money: this.money, //true	int		提现金额
								type: "alipay", //true	string		支付宝:alipay
								real_name: this.userInfo.real_name, //true	string		真实姓名
								account: this.userInfo.alipay_account, //true	string		提现账号
							})
							console.log(res1);
							if (res1.code == 200) {
								uni.showToast({
									title: res1.msg,
									icon: 'none'
								})
								this.getUserInfo()
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			async getUserInfo() {
				let res = await this.$http("api/user/getUserInfo", {}, "GET")
				console.log(res);
				if (res.code == 200) {
					uni.setStorageSync("user", res.result);
					this.userInfo = res.result
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F8FAF7;
	}

	.cashOut {
		padding: 32rpx;

		.amount {
			height: 248rpx;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			padding: 28rpx 24rpx;
			box-sizing: border-box;

			.tit {
				font-weight: bold;
				font-size: 28rpx;
				color: #333333;
			}

			.inp {
				display: flex;
				align-items: center;
				border-bottom: 2rpx solid #CACACA;
				padding: 20rpx 0;

				.rmb {
					font-weight: bold;
					font-size: 48rpx;
					color: #333333;
				}

				.cashinput {
					flex: 1;
					font-weight: 400;
					font-size: 24rpx;
					padding: 8rpx;
				}

				.placStyle {
					font-weight: 400;
					font-size: 24rpx;
					color: #8D8F90;
				}

				.right-btn {
					font-weight: bold;
					font-size: 24rpx;
					color: #FF504A;
				}
			}

			.modelTip {
				font-weight: bold;
				font-size: 24rpx;
				color: #333333;
				padding: 24rpx 0;
			}
		}

		.way {
			height: 196rpx;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin-top: 24rpx;
			padding: 28rpx 24rpx;
			box-sizing: border-box;

			.tit {
				font-weight: bold;
				font-size: 28rpx;
				color: #333333;
				padding-bottom: 20rpx;
			}

			.item {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 164rpx;
				height: 84rpx;
				border-radius: 12rpx 12rpx 12rpx 12rpx;
				border: 2rpx solid #1677FF;
				box-sizing: border-box;
				background-color: #dcebff;

				image {
					width: 36rpx;
					height: 36rpx;
				}

				text {
					font-weight: bold;
					font-size: 24rpx;
					color: #333333;
					padding-left: 4rpx;
				}
			}
		}

		.pageTips {
			height: 168rpx;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			padding: 28rpx 24rpx;
			box-sizing: border-box;
			margin-top: 24rpx;

			.tit {
				font-weight: bold;
				font-size: 28rpx;
				color: #333333;
				padding-bottom: 24rpx;
			}

			.value {
				font-weight: 500;
				font-size: 20rpx;
				color: #8D8F90;
				padding-bottom: 8rpx;
			}
		}

		.confirm-bar {
			width: 556rpx;
			height: 96rpx;
			background: #FF504A;
			border-radius: 68rpx 68rpx 68rpx 68rpx;
			line-height: 96rpx;
			text-align: center;
			font-weight: bold;
			font-size: 32rpx;
			color: #FFFFFF;
			margin: 64rpx auto;
		}
	}
</style>